package com.api.shopapi.mapper;


import com.api.shopapi.entity.ReceiveMessage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ReceiveMessageMapper {

    @Insert("insert into receive_message " +
            "(ReceiveMessageCode,DeviceID,SendMessageCode,sendMessageItemCode,IsHear,NeedRepush,`join`,CreateTime,GovernmentCode) values " +
            "(#{receiveMessage.ReceiveMessageCode},#{receiveMessage.DeviceID},#{receiveMessage.SendMessageCode},#{receiveMessage.SendMessageItemCode},#{receiveMessage.IsHear}," +
            "#{receiveMessage.NeedRepush},#{receiveMessage.Join},#{receiveMessage.CreateTime},#{receiveMessage.GovernmentCode})")
    int insert(@Param("receiveMessage") ReceiveMessage receiveMessage);

    @Select("select * from receive_message where ReceiveMessageCode=#{receiveMessageCode} limit 1")
    ReceiveMessage getByReceiveMessageCode(@Param("receiveMessageCode") String receiveMessageCode);

    @Select("select r.* from send_message_item s,receive_message r " +
            "where GovernmentCode = #{governmentCode} " +
            "and s.SendMessageCode ==#{sendMessageCode} " +
            "AND s.SN = r.DeviceID" +
            "order by CreateTime desc")
    List<ReceiveMessage> getPageListBySendMessageCode(@Param("sendMessageCode")String sendMessageCode,@Param("governmentCode") String governmentCode);
}
